#include "AccusationView.h"

#include <boost/bind.hpp>
#include "../../models/network/CardSetViewModel.h"
#include "../../../utils/LateEvents.hpp"
#include "../../../domain/configuration/NetworkConfiguration.h"

using namespace Views::Remote;
using namespace Utils;

AccusationView::AccusationView(Domain::Network::GameClient* client)
	: client(client)
{
}

void AccusationView::askIfPlayerWantsToPerformAccusation()
{
#ifdef _DEBUG
	std::clog << __FUNCTION__  << std::endl;
#endif
	client->doOnReceiveData(Domain::Configuration::Network::ACCUSATION_DECISION,
		boost::bind(&AccusationView::onDecisionSet, this, _1));
}

void AccusationView::onDecisionSet(sf::Packet packet)
{
	bool decision;
	packet >> decision;
	playerDecisionSetEvent(decision);
}

void AccusationView::askForCardsInAccusation(Cards::CardsCollection cards)
{
	this->cards = cards;
	client->doOnReceiveData(Domain::Configuration::Network::ACCUSATION_CARDS,
		boost::bind(&AccusationView::onCardsSet, this, _1));
}

void AccusationView::onCardsSet(sf::Packet packet)
{
	Views::Models::Network::CardSetViewModel csvm(cards);
	packet >> csvm;
	cardsInAccusationSetEvent(csvm.card_set);
}

